//首页
$.ajax({
	type: "get",
	url: "js/index.json",
	success: function(res) {
		var loading = new createjs.LoadQueue();
		loading.loadManifest(res);
		loading.on("progress", function(event) {
			var num = Math.floor(event.progress * 100);
			$(".loade").html(num + "%");
			if(num == 100) {
				$(".test").css("display", "none");
			};
		});
	},
});
//游戏开始界面
$(".go").on("click", function() {
	$(".game").css("display", "none");
	$(".game_one").css("display", "block")
	if($(".game_one").css("display", "block")) {
		$(".rea").addClass("real");
	};
	if($(".rea").addClass("real")) {
		$(".GO").addClass("gol");
	};
	var k = 1;
	var ste = setInterval(function() {
		k--;
		if(k < 1) {
			clearInterval(ste)
			gameGo();
		}

	}, 500)
});
$(".guze").on("click", function() {
	$(".gui_top").css({
		"transform": "scale(1)"
	});
});
//游戏规则
$(".guibtn").on("click", function() {
	$(".gui_top").css({
		"transform": "scale(0)",
		"transition-duration": "500ms"
	});
});
//开始游戏
function gameGo() {
	$(".time_two").animate({
		width: "0px"
	}, 40000,function(){
		$(this).css("width","97px");
	});
	var arr = ["img/Mc_element0.png", "img/Mc_element1.png", "img/Mc_element2.png", "img/Mc_element3.png", "img/Mc_element4.png"];
	var num = 5;
	var res =0;
	var res1=0;
	var res2=0;
	var tim = setInterval(function() {
		num++;
		var str = Math.floor(Math.random() * 5);
		var str1 = Math.floor(Math.random() *5 + 1);
		var div1 = "<div data-grade='100' class='xi" + str + " xil'><img src=" + arr[str] + "/></div>";
		$(".xij_noe").append(div1);
		$(".xi" + str + "").css({
			top:str+"6%",
			left:str+"2%",
			bottom:str1+"6%",
		}).animate({
			"animation-iteration-count":"1"
		},3000,function(){
			$(this).remove();
		});
		if($(".zha").css("transform","scale(1)")){
			$(".zha").css("transform","scale(0)")
		}
		$(".game_one").on("click", ".xi" + str + "", function() {
			$(this).css("display", 'none');
			var oldGrade = parseInt($(this).data("grade"));
			if(str==0){
				oldGrade = -300;
				$(".zha").css("transform","scale(1)")
			}
			res = res + oldGrade;
			console.log(res,oldGrade);
			$(".gera p").text(res)
			$(".end p").html(res);
		})
		if(num > 41) {
			$(".xij_noe").css("display","none")
			clearInterval(tim)
			$(".finish").css("display","block")
		
		}
	},1000)
	
}
//游戏结束
$(".submit").on("click",function(){
	var reg = /^1[3-9]\d{9}$/;
	var inp = $(".inp").val();
	if(reg.test(inp)==false){
		alert("请输入正确的手机号码")
	}else{
		$(".put").css("display","block");
		$(".finish").css("display","none")
	};
});
//提交成功
$(".flaunt").on("click",function(){
	$(".share").css("display","block");
	$(".put").css("display","none");
});
$(".recur").on("click",function(){
	gameGo();
	$(".put").css("display","none");
	$(".xij_noe").css("display","block");
	$(".gera p").html();
	console.log($(".gera p").html(""));
});
//分享
$(".play").on("click",function(){
	$(".share").css("display","none");
	$(".put").css("display","block");
});
